//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.media;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore.Images.Media;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class ImageProvider {
    private Context context;

    public ImageProvider(Context context) {
        this.context = context;
    }

    public ArrayList<Image> getAllImageList() {
        ArrayList<Image> list = null;
        if(this.context != null) {
            Cursor cursor = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, (String[])null, (String)null, (String[])null, (String)null);
            if(cursor != null) {
                list = new ArrayList();

                while(cursor.moveToNext()) {
                    int id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
                    String title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
                    String path = cursor.getString(cursor.getColumnIndexOrThrow("_data"));
                    String displayName = cursor.getString(cursor.getColumnIndexOrThrow("_display_name"));
                    String mimeType = cursor.getString(cursor.getColumnIndexOrThrow("mime_type"));
                    long size = cursor.getLong(cursor.getColumnIndexOrThrow("_size"));
                    float rotation = cursor.getFloat(cursor.getColumnIndexOrThrow("orientation"));
                    Image audio = new Image(id, title, displayName, mimeType, path, size, rotation);
                    list.add(audio);
                }

                cursor.close();
            }
        }

        return list;
    }

    public Map<String, ArrayList<Image>> getFolderMap() {
        Map<String, ArrayList<Image>> map = new HashMap();
        List<Image> list = this.getAllImageList();
        if(list != null) {
            Iterator var4 = list.iterator();

            while(var4.hasNext()) {
                Image image = (Image)var4.next();
                String folderPath = image.getPath().substring(0, image.getPath().lastIndexOf(File.separator));
                folderPath = folderPath.substring(folderPath.lastIndexOf(File.separator) + 1, folderPath.length());
                String name = image.getPath().substring(image.getPath().lastIndexOf(File.separator), image.getPath().length());
                ArrayList imageList;
                if(map.containsKey(folderPath)) {
                    imageList = (ArrayList)map.get(folderPath);
                    imageList.add(image);
                    map.put(folderPath, imageList);
                } else {
                    imageList = new ArrayList();
                    imageList.add(image);
                    map.put(folderPath, imageList);
                }
            }
        }

        return map;
    }

    public ArrayList<Image> getImageListByFolderName(String folderName) {
        Map<String, ArrayList<Image>> a = this.getFolderMap();
        ArrayList<Image> value = null;
        Iterator ite = a.entrySet().iterator();

        while(ite.hasNext()) {
            Entry<String, ArrayList<Image>> entry = (Entry)ite.next();
            String key = (String)entry.getKey();
            if(key.equals(folderName)) {
                value = (ArrayList)entry.getValue();
            }
        }

        return value;
    }

    public ArrayList<Image> getFolderList() {
        ArrayList<Image> resultList = new ArrayList();
        Map<String, ArrayList<Image>> a = this.getFolderMap();
        Iterator ite = a.entrySet().iterator();

        while(ite.hasNext()) {
            Entry<String, ArrayList<Image>> entry = (Entry)ite.next();
            String key = (String)entry.getKey();
            ArrayList<Image> list = (ArrayList)entry.getValue();
            if(list != null && list.size() > 0) {
                Image image = new Image();
                image.setTitle(key);
                image.setPath(((Image)list.get(0)).getPath());
                image.setPhotoNum(list.size());
                resultList.add(image);
            }
        }

        return resultList;
    }
}
